//
//  ASTableContainer.swift
//  soapp
//
//  Created by tong on 2017/7/18.
//

import UIKit
import Eelay
import AsyncDisplayKit




open class ASTableContainer: ASPaginatorController {
    
    
    open override var sections:TP.section{
        get{
            let sec:TP.section = [
                []
            ]
            return sec
        }
    }
    
    open override var selector:TP.selector{
        get{
            let sel = [
                "<\(page_load_section)>":cellType.self,
                ]
            return sel
        }
    }
    
    public var content:ASTermsContainer?{
        didSet{
            switch self.content! {
            case .as_table(title: let title,emptyMsg:let emptyMsg, net:let net,let params, node: let node, cellType: let cellType, cellHeigth: _, detailType: let detailType,  test:let test):
                self.title = title
                self.cellType = cellType
                self.detailType = detailType
                if let emptyMessage = emptyMsg
                {
                    self.paginator.empty_msg = emptyMessage
                }
                
                if let p = params
                {
                    paginator.parameters = p
                }
                
                paginator.net = net
                paginator.node = node
                paginator.type = .full
                paginator.in_test = test
            case .list(net: let net, node: let node, emptyMsg:let emptyMsg, params: let params, cellType: let cellType, detailType: let detailType, test: let test):
                if let cellTp = cellType as? JoCellNode.Type
                {
                    self.cellType = cellTp
                }
                self.detailType = detailType
                if let emptyMessage = emptyMsg
                {
                    self.paginator.empty_msg = emptyMessage
                }
                
                if let p = params
                {
                    paginator.parameters = p
                }
                
                paginator.net = net
                paginator.node = node
                paginator.type = .full
                paginator.in_test = test
                
            default:
                break
            }
            
        }
    }
    
    public var cellHeigth:CGFloat?
    
    public var detailType:UIViewController.Type?
    
    public var cellType:JoCellNode.Type = JoCellNode.self
    
    public var able = true
    
    public var didSelect:((NSMutableDictionary,ASTableContainer) ->Void)?
    
    public var back_color:UIColor = .table_bg_color
    
    public var viewDidLoadAction:((ASTableContainer)->Void)? = nil
    
    
    public required init()
    {
        super.init()
    }
    
    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override open func viewDidLoad() {
        
        super.viewDidLoad()
        tableView.separatorStyle = .none
        tableView.sectionHeaderHeight = 0
        let v = UIView()
        v.bsui.background(color: back_color)
        tableView.backgroundView = v
        tableView.backgroundColor = back_color
        
//        load(sections: sections, selector: selector)
//        if able
//        {
//            refresh()
//        }
        self.viewDidLoadAction?(self)
    }
    
    
//    open override func tableNode(_ tableNode: ASTableNode, didSelectRowAt indexPath: IndexPath) {
//        if let obj = tableNode.cellData(at: indexPath)
//        {
//            if let detailT = self.detailType
//            {
//                let ctr = detailT.init()
//                if let atr = ctr as? MoAtrributeProtocol
//                {
//                    atr.mo.model = obj
//                }
//
//                self.navigationController?.pushViewController(ctr, animated: true)
//            }
//            if let selectA = self.didSelect
//            {
//                selectA(obj,self)
//            }
//
//        }
//    }
    

    
    
    
}
